<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Music/classes/PhpFox_ComponentFavoriteMusic.class.php, $Author:  $ */



/** Component for viewing favorite music list
 *   
 * @version $Id: PhpFox_ComponentFavoriteMusic.class.php 217 2008-01-23 10:42:31Z phpfoxsv $
 * @package module.music
 */
class PhpFox_Mod_Music_ComponentFavoriteMusic extends BaseComponent
{
    function process()
    {
        $oMusicService = &$this->_oModule->getService('Music');
        /* @var $oMusicService PhpFox_Mod_Music_ServiceMusic */
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oTpl = &$this->_oModule->getTemplate();
        $oReq = &App::getRequest();

        if (!$oSecurityService->checkPerm('music', array('full', 'read_only'), false))
        {
            return '';
        }
        if (!$oSecurityService->checkAccess('music', 'public', false))
        {
            return '';
        }
        if ($iSongId = $oReq->getInt('makeactual'))
        {
            if ($oSecurityService->checkPerm('music', array('full'), false))
            {
                $oMusicService->setActualAccountMusic($iSongId);
            }
            App::gotoUrl();
        }
        if ($iFavoriteId = $oReq->getInt('delete'))
        {
            if ($oSecurityService->checkPerm('music', array('full'), false))
            {
                $oMusicService->deleteFavorite($iFavoriteId);
            }
            App::gotoUrl();
        }
        $oUser = App::loadUser();
        $aSongs = $oMusicService->getFavoriteSongs();
        foreach ($aSongs as $iKey => $aSong)
        {
            $aSongs[$iKey]['song_is_actual'] = $oMusicService->isSongActual($aSong['song_id']);
            $aSongs[$iKey]['song_owner'] = $aSong['user_id'] == $oUser->aData['id'];
        }

        $oTpl->assign(array(
            'aAlbums'    => $oMusicService->getFavoriteAlbums(),
            'aSongs'     => $aSongs,
            'sAlbumsUrl' => App::getParam('music.album.pic.url'),
        ));
        return $oTpl->fetch('FavoriteMusic.html');
    }
}
?>